import { createApp } from 'vue';

// 引入 element-plus 
import ElementUI from 'element-plus';
import 'element-plus/theme-chalk/index.css';
import 'element-plus/theme-chalk/dark/css-vars.css';
 
import './asserts/custom.css';

import pinia from '$aegisStore';

import { createRouter, createWebHistory } from 'vue-router';

/**
 * 创建 Vue 应用
 * @param {*} pageComponent vue 页面组件
 * @param {*} router vue 路由列表
 * @param {*} libs 引入的库
 */
export default (pageComponent, { routes, libs } = {}) => {
    const app = createApp(pageComponent);

    app.use(ElementUI);

    app.use(pinia);


    if ( libs && libs.length > 0) {
        for (let i = 0; i < libs.length; i++) {
            app.use(libs[i]);
        }
    }

    // 创建路由
    if (routes && routes.length > 0) {
        const router = createRouter({
            history: createWebHistory(),
            routes
        });
        app.use(router);
        router.isReady().then(() => {
            app.mount('#root');
        });
    } else {
        app.mount('#root');
    }
}